package top.huxy.boot.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.huxy.boot.mapper.BackupMapper;
import top.huxy.boot.mapper.BlogMapper;
import top.huxy.boot.model.entity.Blog;
import top.huxy.boot.service.BackupService;

import java.util.List;
import java.util.Map;

/**
 * @Classname BackupServiceImpl
 * @Description BackupServiceImpl
 * @Date 2021/10/5 14:41
 * @Created by huxy
 */
@Service
public class BackupServiceImpl implements BackupService {

    @Autowired
    BackupMapper backupMapper;

    @Autowired
    BlogMapper blogMapper;



    @Override
    public List<Map<String, Object>> getBlogBackup() {
        return backupMapper.getBlogBackup();
    }

    @Override
    @Transactional
    public void restoreBackup(List<Blog> blogList) {
        blogMapper.TRUNCATE();
        for (Blog blog : blogList) {
            blogMapper.saveRawBlog(blog);
        }
    }
}
